﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using MyOA.BLL;
using MyOA.Model;

namespace MyOA.UI.ScheduleManage.PersonSchedule
{
    public partial class AllSchedule : System.Web.UI.Page
    {
        AllScheduleManage manage = new AllScheduleManage();
        private int Pager
        {
            set { ViewState["page"] = value; }
            get { return (int)ViewState["page"]; }
        }

        public void dataBind(IList<Schedule> schedules)
        {
            rpSchedule.DataSource = schedules;
            rpSchedule.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["loginId"] == null)
                {
                    Response.Redirect("~/Login.aspx");
                    return;

                }
                
                string loginId = (string)Session["loginId"];
                
                //string loginId=(string)Session["loginId"];
                int userId=manage.getUserIdByLoginId(loginId);
                Session["userId"] = userId;//只给本页使用的SESSION

                Pager = 1;
                int count;
                IList<Schedule> schedules =null;
                schedules = manage.getAllScheduleByUserId(userId,5,Pager,0,out count);
                AspNetPager1.RecordCount =  count;
                AspNetPager1.PageSize = 5;
                dataBind(schedules);
            
               
              
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            Pager = AspNetPager1.CurrentPageIndex;
            if (Session["userId"]!=null)
	        {
    		   int userId=(int)Session["userId"];
               int count;
               IList<Schedule> schedules = manage.getAllScheduleByUserId(userId, 5, Pager, 1, out count);
               dataBind(schedules);
	        }
           
        }
    }
}
